#include"../user.pb.h"
#include"RpcApplication.h"
#include"RpcProvider.h"
#include<iostream>
#include<string>

class userService :public fixbug::UserServiceRpc
{
public:
    bool Login(std::string name,std::string pwd)
    {
        std::cout<<name<<std::endl;
        std::cout<<pwd<<std::endl;
        return true;
    }
   void Login(::google::protobuf::RpcController* controller,
                       const ::fixbug::CG_LOGIN_REQUEST* request,
                       ::fixbug::GC_LOGIN_RESPONSE* response,
                       ::google::protobuf::Closure* done)
    {
        std::string name = request->name();
        std::string pwd = request->pwd();
        bool result = Login(name,pwd);
        if(result)
        {
            fixbug::RESULT_CODE * resultCode = response->mutable_result();
            resultCode->set_errocode(0);
            resultCode->set_erromsg("");
        }
       done->Run();

    }
    bool Register(std::string name,std::string pwd)
    {
        std::cout<<"register"<<std::endl;
        std::cout<<name<<std::endl;
        std::cout<<pwd<<std::endl;
        return true;
    }
   void  Register(::google::protobuf::RpcController* controller,
                       const ::fixbug::CG_LOGIN_REQUEST* request,
                       ::fixbug::GC_LOGIN_RESPONSE* response,
                       ::google::protobuf::Closure* done)
     {
         std::string name = request->name();
         std::string pwd = request->pwd();
        bool result = Register(name,pwd);
        if(result)
        {
            fixbug::RESULT_CODE * resultCode = response->mutable_result();
            resultCode->set_errocode(0);
            resultCode->set_erromsg("");
        }
        done->Run();

     }
     
};
int main(int argc,char ** argv)
{
   RpcApplication::Init(argc,argv);
   RpcProvider rpcProvider;
   rpcProvider.NotifyService(new userService());
   rpcProvider.Run();
   return 0;
}